/**
 * 产品添加
 */
var comValidform = null;
var returnStatus = false;
var productInfoAdd = {
	dataCache : null,
	getResource : function() {
		var url = 'mgr/companyCtrl/list';
		var params = {
			'curPage' : 0,
			'pageSize' : 9999,
			'id' : null,
			'name' : null
		};
		var cb = function(data) {
			if (data.resultCode == 200) {
				var option = '<option value="">请选择发行方</option>';
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					option = option + '<option value="' + singleObj.id + '">'
							+ singleObj.name + '</option>';
				}
				$('select[name="issuerId"]').append(option);
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');

	},

	
	startEvent : function() {
		
		$("select[name='discount']").change();
		
		$("#recordTab ul").idTabs();
		var introduceUE = UE.getEditor('introduce', {
			initialFrameHeight : 340,
			initialFrameWidth : 898
		});
		var incomeUE = UE.getEditor('income', {
			initialFrameHeight : 340,
			initialFrameWidth : 898
		});
		var riskctrlUE = UE.getEditor('riskctrl', {
			initialFrameHeight : 340,
			initialFrameWidth : 898
		});
		
		var signflowUE = UE.getEditor('signflow', {
			initialFrameHeight : 340,
			initialFrameWidth : 898
		});
	
		

		comValidform = $(".com-addForm").Validform({
			datatype : {
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype : 2,
			tipSweep : true,
			beforeSubmit : function(curform) {
				var url = 'mgr/ProductInfoCtrl/saveProductInfo';
				var params = jsUtils.serializeJson($('.com-addForm'));
				var introduce = introduceUE.getContent();
				params.introduce = introduce;

				var income = incomeUE.getContent();
				params.income = income;

				var riskctrl = riskctrlUE.getContent();
				params.riskctrl = riskctrl;
				
				var signflow = signflowUE.getContent();
				params.signflow = signflow;
				
				if(params.discount!=1){
					delete params.discountDate,
					delete params.discountBeginDate;
					delete params.discountEndDate;
					delete params.discountRate;
				}
				
				//更改日期类型
				params.proTerm =params.proTerm *  $("select[name='proTermType']").val();
				delete params.proTermType;
				
				//默认为非热销
				params.hotSale="0";
				var cb = function(data) {
					alert(data.msg);
					// 成功返回
					if (data.resultCode == '200') {
						// 关闭窗口并刷新数据
						art.dialog.close();
						returnStatus = true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	bindEvent: function() {
		//添加贴息事件
		$("select[name='discount']").change(function() {
			if ($("select[name='discount']").val() == 1) {
				$("input[name='discountRate']").attr('type', 'text');
				$("input[name='discountRate']").attr('ignore', '');
				$("input[name='discountEndDate']").attr('type', 'text');
				$("input[name='discountEndDate']").attr('ignore', '');
			} else {
				$("input[name='discountRate']").attr('type', 'hidden');
				$("input[name='discountRate']").attr('ignore', 'ignore');
				$("input[name='discountEndDate']").attr('type', 'hidden');
				$("input[name='discountEndDate']").attr('ignore', 'ignore');
			}
		});
	},

	init : function() {
		productInfoAdd.bindEvent();
		productInfoAdd.getResource();
		productInfoAdd.startEvent();
		
	}
}
$(document).ready(function() {
	productInfoAdd.init();
});
function submitForm() {
	comValidform.submitForm();
	return returnStatus;
}


